<?php
include_once dirname(__FILE__).'/controller.php';
include_once SERVER_ROOT.'/tools/Snoopy.class.php';
class control_geturl extends Controller {
    public function init() {
        $this->url = trim($this->getString('url'));
        $this->right = preg_match('|http://(.*)?|i',$this->url);
    }
    public function index() {
        if ($this->right) {
            $f = fopen($this->url,'r');
            $info = fread($f,2000);
            preg_match('|charset=(.*?)["\']?[\s]?[/]?>|si',$info,$charest);
            if (preg_match('|<title>(.*?)</title>|si',$info,$title) === false) {
                $info = file_get_contents($this->url);
                preg_match('|<title>(.*?)</title>|si',$info,$title);
            }
            if (strtolower(strtolower($charest[1])) != 'utf-8') {
                echo iconv($charest[1],'UTF-8',$title[1]);
            }else {
                echo $title[1];
            }
        }else {
            echo iconv('GBK','UTF-8','无法获取');
        }
    }
}
?>
